package com.webside.playbackstatistics.config;

import java.util.Calendar;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;

import com.webside.Advertisingstatistics.service.AdDailyStatService;
import com.webside.Advertisingstatistics.service.AdProvinceStatService;
import com.webside.Advertisingstatistics.service.AdSingLeStatService;
import com.webside.playbackstatistics.model.AnaDailyStatEntity;
import com.webside.playbackstatistics.service.AnaDailyStatService;
import com.webside.playbackstatistics.service.AnaSummaryStatService;
import com.webside.playbackstatistics.service.PlayStatisticsService;

/***
 * 调度任务
 *
 * @author Administrator
 *
 */
public class RegularStatistics {

	@Autowired
	private PlayStatisticsService playStatisticsService;
	@Autowired
	private AnaDailyStatService anaDailyStatService;
	@Autowired
	private AnaSummaryStatService anaSummaryStatService;
	@Autowired
	private AdDailyStatService adDailyStatService;
	@Autowired
	private AdSingLeStatService adSingleStatService;
	@Autowired
	private AdProvinceStatService adProvinceStatService;

	// 调度定时任务 每天00:01开始执行
	protected void execute() {
		long ms = System.currentTimeMillis();
		System.out.println("\t\t" + new Date(ms) + "第一个方法");
		AnaDailyStatEntity anaDailyStatEntity = playStatisticsService.yesterdaySumCollectStat();
		// 获取昨日日期
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE, -1);
		anaDailyStatEntity.setStatDate(cal.getTime());
		anaDailyStatService.addAnaDailyStat(anaDailyStatEntity);
		System.out.println("\t\t" + new Date(ms) + "第二个方法");
		// 执行统计聚集排名信息之前先删除历史数据
		anaSummaryStatService.deleteAnaSummaryStat();
		anaSummaryStatService.addAnaSummaryStat();
		System.out.println("\t\t" + new Date(ms) + "第三个方法");

		/// 广告统计
		System.out.println("\t\t" + new Date(ms) + "第四个方法");
		adDailyStatService.addadDailyStat();
		// 统计单个广告之前先删除广告统计表的历史数据
		adSingleStatService.deleteAdSingleStat();
		adSingleStatService.addAdSingleStat();
		// 统计广告投放区域信息(添加)
		adProvinceStatService.addadProvinceStat();

	}

}
